import { createRouter, createWebHistory } from 'vue-router'
// 模块路由自动导入
const routeModules = import.meta.glob('./rouets/*.js', { eager: true })
const routes = Object.keys(routeModules).reduce((prev, key) => {
  if (Array.isArray(routeModules[key].default)) {
    prev.push(...routeModules[key].default)
  } else {
    prev.push(routeModules[key].default)
  }
  return prev
}, [])

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

export default router
